//影厅前台service
const name="theaterName"
export default {
  getCinemas: () =>//请求影院数据
    new Promise(resolve => {
      $.ajax({
        url: '/api/theaters/getCinemas',
        type: 'GET',
        success: data => resolve(data)
      });
    }),
  getTheaterList: () =>//请求影厅数据
    new Promise(resolve => {
      $.ajax({
        url: '/api/theaters/getTheaters',
        type: 'GET',
        success: data => resolve(data)
      });
    }),
  addTheater: (newTheater) =>//添加影厅数据
    new Promise(resolve => {
      $.ajax({
        url: '/api/theaters/addTheater',
        type: 'POST',
        data: newTheater,
        success: data => resolve(data)
      });
    }),
  addSeats: (data) =>//添加座位数据
    new Promise(resolve => {
      $.ajax({
        url: '/api/seats/addSeats',
        type: 'POST',
        data: { arryData: JSON.stringify(data) },
        success: data => resolve(data)
      });
    }),
  removeTheater: (data) =>//删除影厅数据
    new Promise(resolve => {
      $.ajax({
        url: `/api/theaters/${data._id}`,
        type: 'DELETE',
        success: data => resolve(data)
      });
    }),
    updateOneTheater:(field,_id)=>//更改影厅数据
      new Promise(resolve => {
        $.ajax({
          url: `/api/theaters/${_id}`,
          type: 'PATCH',
          data:field,
          success: data => resolve(data)
        });
      }),
    setTheater:data=>window.localStorage[name]=JSON.stringify(data),//把数据保存到本地
    getTheater:()=>JSON.parse(window.localStorage[name])//获取本地保存的数据
}